-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Xamarin.Android.Build.Tasks] Fix issue where app will not install #7719
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, this looks good. Moving from <Exec/>
to a custom task seems good.
Is this a "complete" fix? monodroid overrides |
monodroid already handles this scenario via https://github.com/xamarin/androidtools/blob/c3ccfe43cca8092e183706aa2a944a155c1ff7fc/Mono.AndroidTools/Internal/AdbOutputParsing.cs#L341 This was a special case where we did not handle this when installing an |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
bdb23e7
to
bad523e
Compare
@@ -37,5 +42,28 @@ internal override CommandLineBuilder GetCommandLineBuilder () | |||
|
|||
return cmd; | |||
} | |||
|
|||
const string InstallErrorRegExString = @"(?<exception>com.android.tools.build.bundletool.model.exceptions.CommandExecutionException+):(?<error>.+)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand this regex or that it's correct; …CommandExecutionException+:.+
should match n:…
and nn:…
and nnn:…
(etc.). Is this intentional?
What is it supposed to match?
Using the commit message as a guide, it contains:
com.android.tools.build.bundletool.model.exceptions.CommandExecutionException [ToggleDebugReleaseWithSigning/UnnamedProject.csproj]
wherein […/UnnamedProject.csproj]
is presumably added by MSBuild and not by the Android tooling, and thus I can ignore it, but there is also no :
in that line either, so will this regex actually match? Should it match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its supposed to pick up the following from the output com.android.tools.build.bundletool.model.exceptions.CommandExecutionException
.
Once it "detects" that it will then process everything after as part of the error. This is how the error handling works in the JavaTool base class.
I could be using the wrong regex, I tried to copy the existing one from https://github.com/xamarin/xamarin-android/blob/main/src/Xamarin.Android.Build.Tasks/Tasks/JavaToolTask.cs#L68 . I might have got it wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dellis1972: the ExceptionRegExString
regex "ends with" .+
:
const string ExceptionRegExString = @"(?<exception>java.lang.+):(?<error>.+)";
Breaking it down:
(?<exception>java.lang.+)
creates a group named "exception" which starts withjava.lang
and captures everything afterward.- Followed by a colon
:
(?<error>.+)
creates a group named "error" which contains at least one character, capturing until the end of the line.
Note that both (1) and (3) use .+
.
Compare to InstallErrorRegExString
:
const string InstallErrorRegExString = @"(?<exception>com.android.tools.build.bundletool.model.exceptions.CommandExecutionException+):(?<error>.+)";
with:
(?<exception>….CommandExecutionException+)
creates a group named "exception" which starts with….CommandExecutionException
followed by any number ofn
s:CommandExecutionException
,CommandExecutionExceptionn
,CommandExecutionExceptionnn
,CommandExecutionExceptionnnn
…- Followed by a colon
:
(?<error>.+)
creates a group named "error" which contains at least one character, capturing until the end of the line.
(1) is what looks "wrong" to me; I don't think it needs to end with n+
. I believe that the n
could be entirely removed, or we could consider being less restrictive, looking for anything containing .exceptions.
:
const string InstallErrorRegExString = @"(?<exception>.+\.exceptions\..+):(?<error>.+)";
How important is CommandExecutionException
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How important is
CommandExecutionException
?
It seems to be the high level exception which bundletool uses to all of its exceptions. Which is why I wanted to restrict it to this. We can try the more generate one.
I'll just remove the +
for now see if that works.
Commit message for review: [Xamarin.Android.Build.Tasks] Fix issue where app will not install (#7719)
Fixes: https://dev.azure.com/DevDiv/DevDiv/_workitems/edit/1398544
It is quite common for users to switch between Debug and Release
configurations in order to test the app. However, if the `Release`
build is using a custom signing keystore you will generally see this
warning and error:
warning MSB6006: "adb" exited with code 1.
[BT : 1.8.1] error : Installation of the app failed.
This is not entirely helpful, since you often need to dig into the
diagnostic log tofigure out what the actual issue is.
This warning is produced when we try to run
`adb uninstall -k @PACKAGE_NAME@`:
adb uninstall -k com.xamarin.foo
The -k option uninstalls the application while retaining the data/cache.
At the moment, there is no way to remove the remaining data.
You will have to reinstall the application with the same signature, and fully uninstall it.
If you truly wish to continue, execute 'adb shell cmd package uninstall -k'.
We are not entirely sure why the application gets into this state,
but once it does you have to completely uninstall it. We currently
ignore this error but that then results in the following error:
Error: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package com.xamarin.foo signatures do not match newer version; ignoring!
This is because the apps used different signing keystores. As a
result they are incompatible. The only option once you get this issue
is to uninstall the app manually and try again. However the error
messaging is not obvious so users generally have no idea what to do.
Fix a few things in this area. Introduce a new `<AndroidAdb/>` task
which is responsible for making the calls to `adb`. We previously used
`<Exec/>`, which made it hard to make any customizations around error
messaging. We will check the result of the `<AndroidAdb/>` task when
calling `adb uninstall -k @PACKAGE_NAME@` and if the output contains
`adb shell cmd package uninstall` then we will automatically call
`adb shell cmd package uninstall @PACKAGE_NAME@`. This will completely
remove the app from the device and will allow the later `bundletool`
invocation to work.
We have also updated `<InstallApkSet/>` to look for error messages from
`bundletool` and report them, so users will get better information.
We now generate error messages like:
[BT : 1.8.1] error : Installation of the app failed.
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: The APKs have been extracted in the directory: /var/folders/5p/10yqy2kx6r9dnmnxh_nt6s0r0000gn/T/1389125984700138671
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: 01:54:24 E/SplitApkInstallerBase: Failed to commit install session 1426763565 with command cmd package install-commit 1426763565. Error: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package com.xamarin.toggledebugreleasewithsigning signatures do not match newer version; ignoring!
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: [BT:1.8.1] Error: Installation of the app failed.
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: com.android.tools.build.bundletool.model.exceptions.CommandExecutionException
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: Installation of the app failed.
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.model.exceptions.InternalExceptionBuilder.build(InternalExceptionBuilder.java:57)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.device.DdmlibDevice.installApks(DdmlibDevice.java:192)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.commands.InstallApksCommand.lambda$execute$2(InstallApksCommand.java:214)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.device.AdbRunner.run(AdbRunner.java:81)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.device.AdbRunner.run(AdbRunner.java:43)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.commands.InstallApksCommand.execute(InstallApksCommand.java:214)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:91)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:49)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: Caused by: com.android.ddmlib.InstallException: Failed to commit install session 1426763565 with command cmd package install-commit 1426763565. Error: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package com.xamarin.toggledebugreleasewithsigning signatures do not match newer version; ignoring!
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.ddmlib.SplitApkInstallerBase.installCommit(SplitApkInstallerBase.java:99)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:85)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.ddmlib.internal.DeviceImpl.installPackages(DeviceImpl.java:1166)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.device.DdmlibDevice.installApks(DdmlibDevice.java:176)
obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: ... 6 more
Unit Test are added. |
Fixes https://i.azdo.io/1398544 It is quite common for users to switch from Debug to Release mode in order to test the app. However if the `Release` build is using a custom signing keystore you will generally see this warning and error. ``` warning MSB6006: "adb" exited with code 1. [BT : 1.8.1] error : Installation of the app failed. ``` This is not entirely helpful. Since you need to dig into the log to figure out what the actual issue is. The warning is produced when we try to run `adb uninstall -k <package>`. ``` adb uninstall -k com.xamarin.foo (TaskId:361) The -k option uninstalls the application while retaining the data/cache. (TaskId:361) At the moment, there is no way to remove the remaining data. (TaskId:361) You will have to reinstall the application with the same signature, and fully uninstall it. (TaskId:361) If you truly wish to continue, execute 'adb shell cmd package uninstall -k'. ``` We are not entirely sure why the application gets into this state. But once it does you have to completely uninstall it. We currently ignore this error but that then results in the following. ``` Error: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package com.xamarin.toggledebugreleasewithsigning signatures do not match newer version; ignoring! ``` This is because the apps have different signing keystores. As a result they are incompatible. The only option once you get this issue is to uninstall the app manually and try again. However the error messaging is not obvious so users generally have no idea what to do. So lets fix a few things wrong in this area. Firstly lets introduce a new task `AndroidAdb` which is responsible for making the calls to `adb`. We currently use `Exec` which means its hard to make any customizations around error messaging. We will check the result of `AndroidAdb` when calling `adb uninstall -k <package>` and if we get message we will automatically fall back on calling `adb shell cmd package uninstall`. This will completely remove the app from the device and will allow the later `bundletool` call to work. We have also updated `InstallApkSet` to look for error messages from `bundletool` and report them, so users will get better information. So we now get error messages like ``` [BT : 1.8.1] error : Installation of the app failed. [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: The APKs have been extracted in the directory: /var/folders/5p/10yqy2kx6r9dnmnxh_nt6s0r0000gn/T/1389125984700138671 [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: 01:54:24 E/SplitApkInstallerBase: Failed to commit install session 1426763565 with command cmd package install-commit 1426763565. Error: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package com.xamarin.toggledebugreleasewithsigning signatures do not match newer version; ignoring! [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: [BT:1.8.1] Error: Installation of the app failed. [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: com.android.tools.build.bundletool.model.exceptions.CommandExecutionException [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: Installation of the app failed. [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.model.exceptions.InternalExceptionBuilder.build(InternalExceptionBuilder.java:57) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.device.DdmlibDevice.installApks(DdmlibDevice.java:192) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.commands.InstallApksCommand.lambda$execute$2(InstallApksCommand.java:214) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.device.AdbRunner.run(AdbRunner.java:81) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.device.AdbRunner.run(AdbRunner.java:43) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.commands.InstallApksCommand.execute(InstallApksCommand.java:214) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:91) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:49) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: Caused by: com.android.ddmlib.InstallException: Failed to commit install session 1426763565 with command cmd package install-commit 1426763565. Error: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package com.xamarin.toggledebugreleasewithsigning signatures do not match newer version; ignoring! [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.ddmlib.SplitApkInstallerBase.installCommit(SplitApkInstallerBase.java:99) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:85) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.ddmlib.internal.DeviceImpl.installPackages(DeviceImpl.java:1166) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: at com.android.tools.build.bundletool.device.DdmlibDevice.installApks(DdmlibDevice.java:176) [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: ... 6 more [ToggleDebugReleaseWithSigning/UnnamedProject.csproj] obj/Release/android/bin/com.xamarin.toggledebugreleasewithsigning.apks : java error BT0000: ``` Unit Test also added.
* main: [Xamarin.Android.Build.Tasks] Fix issue where app will not install (dotnet#7719) Bump to dotnet/installer@779a644 8.0.100-alpha.1.23070.23 (dotnet#7728) LEGO: Merge pull request 7751 [Mono.Android] Wrap connection exceptions in HttpRequestException (dotnet#7661) [Mono.Android] Fix View.SystemUiVisibility enumification (dotnet#7730)
* main: [Xamarin.Android.Build.Tasks] Fix issue where app will not install (dotnet#7719) Bump to dotnet/installer@779a644 8.0.100-alpha.1.23070.23 (dotnet#7728) LEGO: Merge pull request 7751 [Mono.Android] Wrap connection exceptions in HttpRequestException (dotnet#7661) [Mono.Android] Fix View.SystemUiVisibility enumification (dotnet#7730) Bump r8 from 3.3.75 to 4.0.48 (dotnet#7700) [monodroid] Prevent overlapped decompression of embedded assemblies (dotnet#7732) [xaprepare] Support arm64 emulator components (dotnet#7743) Bump SQLite to 3.40.1 (dotnet#7733) Bump to xamarin/xamarin-android-binutils/L_15.0.7-5.0.3@6721af4b (dotnet#7742) [monodroid] Replace `exit()` with `abort()` in native code (dotnet#7734) Bump to xamarin/Java.Interop/main@8a1ae57 (dotnet#7738) [build] bump `$(AndroidNet7Version)` (dotnet#7737) Bump to xamarin/Java.Interop/main@1366d99 (dotnet#7718) [Xamarin.Android.Build.Tasks] fix AndroidGenerateResourceDesigner (dotnet#7721) Bump to xamarin/monodroid@50faac94 (dotnet#7725)
* main: (112 commits) [ci] Remove classic Mono.Android-Tests runs (dotnet#7778) $(AndroidPackVersionSuffix)=preview.2; net8 is 34.0.0-preview.2 (dotnet#7761) Localized file check-in by OneLocBuild Task (dotnet#7758) Bump to dotnet/installer@dec1209 8.0.100-alpha.1.23080.11 (dotnet#7755) LEGO: Merge pull request 7756 Localized file check-in by OneLocBuild (dotnet#7752) [Xamarin.Android.Build.Tasks] Fix issue where app will not install (dotnet#7719) Bump to dotnet/installer@779a644 8.0.100-alpha.1.23070.23 (dotnet#7728) LEGO: Merge pull request 7751 [Mono.Android] Wrap connection exceptions in HttpRequestException (dotnet#7661) [Mono.Android] Fix View.SystemUiVisibility enumification (dotnet#7730) Bump r8 from 3.3.75 to 4.0.48 (dotnet#7700) [monodroid] Prevent overlapped decompression of embedded assemblies (dotnet#7732) [xaprepare] Support arm64 emulator components (dotnet#7743) Bump SQLite to 3.40.1 (dotnet#7733) Bump to xamarin/xamarin-android-binutils/L_15.0.7-5.0.3@6721af4b (dotnet#7742) [monodroid] Replace `exit()` with `abort()` in native code (dotnet#7734) Bump to xamarin/Java.Interop/main@8a1ae57 (dotnet#7738) [build] bump `$(AndroidNet7Version)` (dotnet#7737) Bump to xamarin/Java.Interop/main@1366d99 (dotnet#7718) ...
Fixes https://i.azdo.io/1398544
It is quite common for users to switch from Debug to Release mode in
order to test the app. However if the
Release
build is using a customsigning keystore you will generally see this warning and error.
This is not entirely helpful. Since you need to dig into the log to
figure out what the actual issue is.
The warning is produced when we try to run
adb uninstall -k <package>
.We are not entirely sure why the application gets into this state. But
once it does you have to completely uninstall it. We currently ignore
this error but that then results in the following.
This is because the apps have different signing keystores. As a result
they are incompatible. The only option once you get this issue is to
uninstall the app manually and try again. However the error messaging
is not obvious so users generally have no idea what to do.
So lets fix a few things wrong in this area. Firstly lets introduce a
new task
AndroidAdb
which is responsible for making the calls toadb
.We currently use
Exec
which means its hard to make any customizationsaround error messaging. We will check the result of
AndroidAdb
whencalling
adb uninstall -k <package>
and if we get message we willautomatically fall back on calling
adb shell cmd package uninstall
.This will completely remove the app from the device and will allow the
later
bundletool
call to work.We have also updated
InstallApkSet
to look for error messages frombundletool
and report them, so users will get better information. Sowe now get error messages like
Unit Test also added.